<template>
  <div v-show="$route.name === 'store-loss-detail'">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/store-loss-list' }">损耗记录详情
    </el-breadcrumb-item>
      <el-breadcrumb-item>损耗记录详情</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域--订单数据修改 -->
    <el-card>
      <el-row>
        <el-col :span="24">
          <el-date-picker type="date" placeholder="选择日期" readonly v-model="apply_date">
          </el-date-picker>
        </el-col>
      </el-row>
      <el-table
      border
      v-loading="loading"
      :data="lossData"
      style="margin-top: 10px;">
        <el-table-column type="index" width="60" align="center"></el-table-column>
        <el-table-column label="分类" prop="category_name" min-width="130" align="center"></el-table-column>
        <el-table-column label="商品" prop="name" min-width="130" align="center"></el-table-column>
        <el-table-column label="损耗前数量" prop="count_before" min-width="80" align="center"></el-table-column>
        <el-table-column label="损耗后数量" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ parseFloat(scope.row.count_before - scope.row.count).toFixed(2) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="comment" min-width="180" align="center"></el-table-column>
      </el-table>
      <el-row>
        <el-col :span="24">
          <el-button  @click="back" style="margin-left: 5px;margin-top: 10px;">返回</el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loss_id: '',
      lossData: [],
      apply_date: '',
      loading: false,
      groupid: ''
    }
  },
  mounted() {
    this.getUserInfo()
    this.getlossData()
   },
   methods: {
    // 获取用户信息
    async getUserInfo() {
      const { data: result } = await this.$http.get('/user/' + localStorage.userid)
      if (result.status !== 200) return this.$message.error(result.msg)
      this.groupid = result.data.groupid * 1
    },
    getlossData() {
      if (this.$route.params.loss_id) {
        this.loss_id = this.$route.params.loss_id
        localStorage.setItem('lossId', this.$route.params.loss_id)
      } else {
        this.loss_id = localStorage.getItem('lossId')
      }
      if (this.loss_id) {
        this.getLossDetail(this.loss_id)
      }
    },
    async getLossDetail(loss_id) {
      const { data: result } = await this.$http.get('/store-loss/' + loss_id)
      if (result.status !== 200) {
        this.loading = false
        return this.$message.error(result.msg)
      }
      this.loading = false
      this.lossData = result.data.detail
      this.apply_date = result.data.apply_date
    },
    back () {
      localStorage.removeItem('lossId')
      this.$router.push({ 'name': 'store-loss-list' })
    }
  }
}
</script>